/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package DsrvMain.bl;

import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import DsrvMain.persistence.controllers.T001UserJpaController;
import DsrvMain.persistence.entities.T001User;

/**
 *
 * @author a381u296
 */
public class DsrvMainPerson {

    private final EntityManagerFactory emf = Persistence.createEntityManagerFactory("DsrvMainDBPU");
    private final T001UserJpaController tujc = new T001UserJpaController(emf);
    
    private T001User user ;
   
    private String error_msg;

    public DsrvMainPerson() {
        this.error_msg = "OK";
    }

    public String getError_msg() {
        return error_msg;
    }
    
    


    public T001User findUsername (String username){
        
         try {
             user = (T001User) tujc.getEntityManager()
                    .createNamedQuery("T001User.findByUsername")
                    .setParameter("username", username) // 
                    .getSingleResult();
             
        } catch (Exception e) {
            user = null;
            error_msg = e.getMessage();
        }
        
        return user;
    }

}
